
;(function ($) {
    $.fn.autoHideNav = function () {
        var mainHeader = $(this);
        var headerHeight = mainHeader.height();

        var scrolling = false,
            previousTop = 0,
            currentTop = 0,
            scrollDelta = 10,
            scrollOffset = 150;

        $(window).on('scroll.header', function () {
            if (!scrolling) {
                scrolling = true;
                (!window.requestAnimationFrame) ? setTimeout(autoHideHeader, 250): requestAnimationFrame(autoHideHeader);
            }
        })

        function autoHideHeader() {
            var currentTop = $(window).scrollTop();
            checkSimpleNavigation(currentTop);
            previousTop = currentTop;
            scrolling = false;
        }

        function checkSimpleNavigation(currentTop) {
            if (currentTop - previousTop > scrollDelta && currentTop > scrollOffset) {
                mainHeader.addClass('is-hidden');
            } else if (previousTop - currentTop > scrollDelta) {
                mainHeader.removeClass('is-hidden');
            }
        }
    }
})(jQuery);